﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using Zero.POCO.Views;

namespace DevExpress.MailClient.Win.Controls.ProfilPenetration.Maximized
{
    public partial class WidgetInstructionMaximized : DevExpress.XtraEditors.XtraUserControl
    {
        public WidgetInstructionMaximized()
        {
            InitializeComponent();
        }

        public void UpdateStat(ProfilPenetrationView profilPenetrationView)
        {
            ccSupport.Series.Clear();
            var series1 = new Series(profilPenetrationView.ProfilPrincipale.ProfilPrincipale.SupportView.Nom, ViewType.Bar);

            series1.Points.Add(new SeriesPoint("Moyen", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Moyen * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreMoyen));
            series1.Points.Add(new SeriesPoint("Primaire", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Primaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombrePrimaire));
            series1.Points.Add(new SeriesPoint("Sans instruction", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.SansInstruction * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstruction));
            series1.Points.Add(new SeriesPoint("Sans instruct/lire et écrire", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.SansInstructionLireEtEcrire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstructionLireEtEcrire));
            series1.Points.Add(new SeriesPoint("Secondaire", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Secondaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSecondaire));
            series1.Points.Add(new SeriesPoint("Universitaire", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Universitaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreUniversitaire));
            series1.SeriesPointsSorting = SortingMode.Descending;
            ccSupport.Series.Add(series1);


            foreach (var profilPenetrationSup in profilPenetrationView.ProfilPrincipale.ProfilSupport)
            {
                var series2 = new Series(profilPenetrationSup.SupportView.Nom, ViewType.Bar);

                series2.Points.Add(new SeriesPoint("Moyen", profilPenetrationSup.StatistiqueInstruction.Moyen * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreMoyen));
                series2.Points.Add(new SeriesPoint("Primaire", profilPenetrationSup.StatistiqueInstruction.Primaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombrePrimaire));
                series2.Points.Add(new SeriesPoint("Sans instruction", profilPenetrationSup.StatistiqueInstruction.SansInstruction * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstruction));
                series2.Points.Add(new SeriesPoint("Sans instruct/lire et écrire", profilPenetrationSup.StatistiqueInstruction.SansInstructionLireEtEcrire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstructionLireEtEcrire));
                series2.Points.Add(new SeriesPoint("Secondaire", profilPenetrationSup.StatistiqueInstruction.Secondaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSecondaire));
                series2.Points.Add(new SeriesPoint("Universitaire", profilPenetrationSup.StatistiqueInstruction.Universitaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreUniversitaire));

                series2.SeriesPointsSorting = SortingMode.Descending;
                ccSupport.Series.Add(series2);    
            }

            // Format the the series labels.
            series1.Label.TextPattern = "{A}: {VP:p0}";

            List<int> listVague = profilPenetrationView.ProfilSupport.Select(e => e.Vague.Mois).ToList();
            listVague.Sort();



            ccVagueSupport.Series.Clear();
            var series_1 = new Series("Moyen", ViewType.Line);

          

            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_1.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.Moyen * 100 / profilPenetrationSup.Vague.NombreMoyen));
            }
            series_1.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Moyen * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreMoyen));

            ccVagueSupport.Series.Add(series_1);








            var series_2 = new Series("Primaire", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_2.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.Primaire * 100 / profilPenetrationSup.Vague.NombrePrimaire));
            }
            series_2.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Primaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombrePrimaire));

            ccVagueSupport.Series.Add(series_2);



            var series_3 = new Series("SansInstruction", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_3.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.SansInstruction * 100 / profilPenetrationSup.Vague.NombreSansInstruction));
            }
            series_3.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.SansInstruction * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstruction));

            ccVagueSupport.Series.Add(series_3);





            var series_4 = new Series("SansInstruction/sait lire ecrire", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_4.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.SansInstructionLireEtEcrire * 100 / profilPenetrationSup.Vague.NombreSansInstructionLireEtEcrire));
            }
            series_4.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.SansInstructionLireEtEcrire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSansInstructionLireEtEcrire));

            ccVagueSupport.Series.Add(series_4);



            var series_5 = new Series("Secondaire", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_5.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.Secondaire * 100 / profilPenetrationSup.Vague.NombreSecondaire));
            }
            series_5.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Secondaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSecondaire));

            ccVagueSupport.Series.Add(series_5);




            var series_6 = new Series("Universitaire", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_6.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueInstruction.Universitaire * 100 / profilPenetrationSup.Vague.NombreUniversitaire));
            }
            series_6.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueInstruction.Universitaire * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreUniversitaire));

            ccVagueSupport.Series.Add(series_6);
        }
    }
}
